<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="resourceList">
      <el-table-column type="index" label="序号" width="55" align="center">
        <template slot-scope="scope">
          {{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index +1}}
        </template>
      </el-table-column>
      <el-table-column label="项目号" align="center" prop="projectNo" />
      <el-table-column label="项目描述" align="center" prop="detail" min-width="200" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleLook(scope.row)"
          >查看附件</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="附件列表" :visible.sync="open" width="80%" append-to-body>
      <el-tree :data="fileList" :props="defaultProps" @node-click="handlePreview"></el-tree>
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm" v-loading="btnLoading">打 印</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
    </el-dialog>
  </div>
</template>

<script>
import { listResource, getFileList } from "@/api/wms/resource";

export default {
  name: "Resource",
  dicts: ['wms_contract_status','sys_yes_no'],
  data() {
    return {
      prefix: process.env.VUE_APP_BASE_API,
      //按钮加载
      btnLoading: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资金管理表格数据
      resourceList: [],
      // 是否显示弹出层
      open: false,
      openPrint: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: null,
        offerCode: null,
        inquireCode: null,
        status: null
      },
      // 附件列表
      fileList: [],
      defaultProps: {
        children: 'children',
        label: 'fileName'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询资金管理列表 */
    getList() {
      this.loading = true;
      listResource(this.queryParams).then(response => {
        this.resourceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm() {
      if(this.fileList.length > 0) {
        this.open = false
        this.openPrint = true
      } else {
        this.$modal.msgError("没有附件不可打印")
      }
    },
    handleLook(row) {
      getFileList({orderCode: row.orderCode, inquireCode: row.inquireCode}).then(response => {
        this.fileList = response;
        this.fileList.forEach(file => {
          file.url = this.prefix  + file.url
        })
        this.open = true
      });
    },
    // 文件点击事件
    handlePreview(file){
      if (file.flag === '1') {
        window.open(this.prefix + file.url,'_blank');
      }
    },
  }
};
</script>
